using System;
using System.Windows.Forms;

namespace VirtualManagerSA
{
	/// <summary>
	/// This class holds all of the variables necessary for any given employee to hold
	/// at any time: both those stored in the database, and more temporary ones. Though
	/// it never directly interacts with the database, it is a convenient encapsulation of
	/// everything related to the employee.
	/// </summary>
	public class Employee
	{
		/*Global Variables*/
		string userid;
		string username;
		string time;
		string shift;
		string availability;
		string password;
		DateTime[] daysOff;
		int shiftCount;
		int totalAvailability; //aka the pickiness factor
		string partTime;
		float weight;

		//Set the "weight" of a given employee at any time during the schedule generation.
		public void setWeight(float w)
		{
			weight=w;
		}

		//Get the "weight" of a given employee at any time during the schedule generation
		public float getWeight()
		{
			return weight;
		}

		//Returns "yes" if the employee is part time, and "no" if they are full time.
		public string getPartTime() 
		{
			return partTime;
		}

		//Sets whether or not the employee is part time.
		public void setPartTime(string part) 
		{
			partTime = part;
		}

		//A boolean implementation of "getPartTime()".
		public bool isPartTime()
		{
			if(partTime.Equals("yes"))
				return true;
			return false;
		}
		
		//Sets the array of DateTimes that represents this employee's requested days off.
		public void setDaysOff(DateTime[] d) 
		{
			daysOff = d;
		}

		//Given a DateTime, this method will return true if the employee has requested that day off, and false otherwise.
		public bool checkDay(DateTime d) 
		{
			for (int i = 0; i < daysOff.Length; i++) 
			{
				if ((d.Date==daysOff[i].Date)&&(d.Month==daysOff[i].Month)&&(d.Year==daysOff[i].Year)) 
				{
					return true;
				}
			}
			return false;
		}
		
		//Basic (and unused) constructor.
		public Employee()
		{
			userid = "";
			username = "";
			time = "";
			shift = "";
			availability = "11111111111111";//Sets the employee available for all days & times.
			password = "";
			shiftCount = 0;
		}

		//Constructor that includes all employee variables (except for days off, which is implemented elsewhere.)
		public Employee(string uid, string uname, string t, string s, string avail, string pass, string part) 
		{
			userid = uid;
			username = uname;
			time = t;
			shift = s;
			availability = avail;
			password = pass;
			shiftCount = 0;
			partTime = part;
		}

		//Returns the MD5 hash of the employee's password that was stored in the database.
		public string getPassword() 
		{
			return password;
		}

		//Sets the employee's password.
		public void setPassword(string pass) 
		{
			password = pass;
		}

		//Returns the employee's username.
		public string getName() 
		{
			return username;
		}

		//Returns the employee's userid.
		public string getId() 
		{
			return userid;
		}

		//Returns the employee's preference as to AM, PM, or no preference.
		public string getTimes() 
		{
			return time;
		}

		//Returns the employee's preference as to working single or double shifts (or no preference).
		public string getShifts() 
		{
			return shift;
		}

		//Returns the employee's availability for the 14 possible shifts in the form of a 14-character string.
		//The shifts go in order of Sunday AM, Sunday PM, Monday AM, Monday PM, etc., and the character '0' means
		//unavailable for that shift, and '1' means available.
		public string getAvailability() 
		{
			return availability;
		}

		//Returns the total number of shifts this employee has been supplied so far in this schedule generation routine.
		public int getShiftCount()
		{
			return shiftCount;
		}

		//Increments the total  number of shifts this employee has been supplied in this schedule generation routine.
		public void incShiftCount()
		{
			shiftCount++;
		}
		
		//Sets the employee's preference as to AM or PM shifts.
		public void setTimes(string t) 
		{
			time = t;
		}

		//Sets the employee's preference as to single or double shifts.
		public void setShifts(string s) 
		{
			shift = s;
		}

		//Sets the availability string (described above in getAvailability()).
		public void setAvailability(string avail) 
		{
			availability = avail;
		}

		//Takes an index and a string containing one character, replaces that character in availability
		public void setAvailability(int i,string newChar)
		{
			string newAvail="";
			for(int j=0; j<14; j++)
			{
				if(i==j)
					newAvail+=newChar;
				else
					newAvail+=availability[j];
			}
			availability=newAvail;
		}

		//Returns the "pickiness" at this point during schedule generation.
		public int getTotalAvailability()
		{
			return totalAvailability;
		}

		//Sets the "pickiness" at this point during schedule generation.
		public void setTotalAvailability(int n)
		{
			totalAvailability=n;
		}

		//Returns whether or not an employee has already been assigned a specific shift in this schedule generation runthrough.
		public bool isWorking(string[,] schedule, int shift, int perShift)
		{
			for(int i=0; i<perShift; i++)
			{
				if(username==schedule[shift,i])
					return true;
			}
			return false;
		}
	}
}
